from __future__ import absolute_import, division, print_function, unicode_literals
import re
#import tensorflow as tf
from PIL import Image
import keras
#from tensorflow import keras
from keras.preprocessing import image
from keras.preprocessing.image import img_to_array
from keras.applications.imagenet_utils import preprocess_input
from keras.applications.imagenet_utils import decode_predictions
from keras.models import Sequential
from keras.layers import Dense
from sklearn.preprocessing import MinMaxScaler
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
#print(tf.__version__)
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
train_images = train_images / 255.0

test_images = test_images / 255.0

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
model = keras.Sequential([    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=15)

test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print("test_acc",test_acc)
# model_json = model.to_json()
# with open("model.json", "w") as json_file:
#     json_file.write(model_json)

model.save('111.h5')
:
这是加载模型进行预测
:
from __future__ import absolute_import, division, print_function, unicode_literals
import re
from PIL import Image
import keras
from keras.preprocessing import image
from keras.preprocessing.image import img_to_array
from keras.applications.imagenet_utils import preprocess_input
from keras.applications.imagenet_utils import decode_predictions
from keras.models import Sequential
from keras.layers import Dense
from sklearn.preprocessing import MinMaxScaler
# Helper libraries
import numpy as np

from __future__ import absolute_import, division, print_function, unicode_literals
import re
#import tensorflow as tf
from PIL import Image
import keras
#from tensorflow import keras
from keras.preprocessing import image
from keras.preprocessing.image import img_to_array
from keras.applications.imagenet_utils import preprocess_input
from keras.applications.imagenet_utils import decode_predictions
from keras.models import Sequential
from keras.layers import Dense
from sklearn.preprocessing import MinMaxScaler
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
#print(tf.__version__)
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
train_images = train_images / 255.0

test_images = test_images / 255.0

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
model = keras.Sequential([    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=15)

test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print("test_acc",test_acc)
# model_json = model.to_json()
# with open("model.json", "w") as json_file:
#     json_file.write(model_json)

model.save('111.h5')

from __future__ import absolute_import, division, print_function, unicode_literals
import re
from PIL import Image
import keras
from keras.preprocessing import image
from keras.preprocessing.image import img_to_array
from keras.applications.imagenet_utils import preprocess_input
from keras.applications.imagenet_utils import decode_predictions
from keras.models import Sequential
from keras.layers import Dense
from sklearn.preprocessing import MinMaxScaler
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
class_name_china=['t恤/上衣','裤子','套衫','连衣裙','外套','凉鞋',
'衬衫','运动鞋','包','短靴']

from keras.models import load_model
model = load_model('111.h5')

def yuce(image):
    plt.imshow(image)
    plt.show()
    image_list = np.expand_dims(image, axis=0)
    preds = model.predict_classes(image_list)
    print(preds)
    print(class_name_china[preds[0]])
    #print(test_labels)
    return class_name_china[preds[0]]

import json
from flask import Flask,escape,request,Response
import matplotlib.pyplot as plt
from src.llt import yuce
import matplotlib.image as img

app = Flask(__name__)


@app.route('/test2', methods=['GET', 'POST'])
def getimage():
    file = request.files.get('file')
    result = img.imread(file)
    lable=yuce(result)
    return str(lable)
if __name__ == "__main__":
    app.run(host='0.0.0.0',port=5000)